#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/3/17 17:01
# @Author : linjinting
# @Project : Flask-WebService
# @File : base.py
# @Software: PyCharm

from .readconfig import ReadConfig


class Config(object):
    def __init__(self):
        self.m_config = None
        self.m_config_obj = dict()

    def form_file(self, file=None):
        rc = ReadConfig(file)
        self.m_config = rc.get_config_dict()

        for k, v in self.m_config.items():
            self.m_config_obj[k] = DictAddAttr(v)

    def get_config(self):
        return self.m_config

    def get_config_obj(self):
        return self.m_config_obj


class DictAddAttr(dict):
    def __init__(self, config):
        super().__init__(config)
        self.__dict__ = self
        # for k, v in config.items():
        #     if 'port' == k:
        #         v = int(v)
        #     self[k] = v

    # def __getattr__(self, item):
    #     return self[item]
    #
    # def __setattr__(self, key, value):
    #     self[key] = value


# class _MysqlConfig(dict):
#     def __init__(self, config):
#         super().__init__()
#         mysql_config = config.get('mysql', {})
#
#         for k, v in mysql_config.items():
#             if 'port' == k:
#                 v = int(v)
#             self[k] = v
#
#
# class _Recv(dict):
#     def __init__(self, config):
#         super().__init__()
#         server_config = config.get('recv', {})
#
#         for k, v in server_config.items():
#             self[k] = v
#
#
# class _Send(dict):
#     def __init__(self, config):
#         super().__init__()
#         server_config = config.get('send', {})
#
#         for k, v in server_config.items():
#             self[k] = v
